Skip to content

fix: clamp oversized retry value to the maximum timer delay - #392

Open
feliciovcm wants to merge 3 commits into
EventSource:mainfrom
feliciovcm:fix/clamp-retry-interval
Open

feliciovcm wants to merge 3 commits into
EventSource:mainfrom
feliciovcm:fix/clamp-retry-interval

Conversation

@feliciovcm

Copy link
Copy Markdown

Problem

A server can send retry: with a value above 2147483647 (2^31-1). #onRetryChange stores it as is and setTimeout(this.#reconnect, this.#reconnectInterval) receives it as the delay. Timers do not accept delays above that limit and fire immediately instead. In a browser tab, setTimeout(fn, 2147483648) ran its callback after 0 ms.

For the client this means that after the connection closes, it reconnects without waiting, over and over, for as long as the server keeps sending the large retry value.

Fix

Clamp the stored reconnection interval to 2147483647 ms in #onRetryChange, the largest delay a timer accepts.

Test

Adds a test that serves a stream containing retry: 2147483648, closes it, and checks that only one fetch happens in the following 250 ms. Includes a patch changeset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant